package com.example.binpacking.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.binpacking.mapper.InterviewerMapper;
import com.example.binpacking.model.Interviewer;
import com.example.binpacking.service.InterviewerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.math.BigDecimal;
import java.util.List;

@Service
@Transactional
public class InterviewerServiceImpl implements InterviewerService {
    @Autowired
    private InterviewerMapper interviewerMapper;

    @Override
    public Interviewer login(Interviewer interviewer) {
        String loginid =interviewer.getLoginid();
        String password = interviewer.getPassword();
//        String usertype = interviewer.getUsertype();
        QueryWrapper<Interviewer> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("loginid", loginid)
                .eq("password", password)
                ;
        return interviewerMapper.selectOne(queryWrapper);
    }

    @Override
    public List<Interviewer> findByLoginIdAndPassword(BigDecimal loginid, String password) {
        return interviewerMapper.findByLoginIdAndPassword(loginid,password);
    }

//    @Override
//    public Interviewer login(BigDecimal loginid, String password, String usertype) {
//
//        // MD5加密密码
////        String encryptedPassword = DigestUtils.md5Hex(password);
//
//        QueryWrapper<Interviewer> queryWrapper = new QueryWrapper<>();
//        queryWrapper.eq("loginid", loginid)
//                .eq("password", password)
//                .eq("usertype", usertype);
//
//        return interviewerMapper.selectOne(queryWrapper);
//    }
public IPage<Interviewer> getInterviewerByPage(int currentPage, int pageSize) {
    Page<Interviewer> page = new Page<>(currentPage, pageSize);
    return interviewerMapper.selectPage(page, null);
}

}
